﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Kooboo.CMS.Form;
using Kooboo.CMS.Form.Html;
using Kooboo.Globalization;

namespace KB.Controls
{
    public class DateTime : Kooboo.CMS.Form.Html.Controls.Input
    {
        public override string Type
        {
            get { return "text"; }
        }

        private string _name;
        public override string Name
        {
            get
            {
                if (string.IsNullOrEmpty(_name))
                {
                    _name = this.GetType().Name;
                }

                return _name;
            }
        }

        /// <summary>
        /// false
        /// </summary>
        protected virtual bool AllowMultipleFiles
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// /^.+\..+$/
        /// </summary>
        protected virtual string Validation
        {
            get
            {
                return @"/^\d{2}/\d{2}/\d{4}\s\d{2}\d{2}$/";
            }
        }

        /// <summary>
        /// Please select a valid file
        /// </summary>
        protected virtual string ValidationErrorMessage
        {
            get
            {
                return "The datetime format is incorrect";
            }
        }

        protected override string RenderInput(Kooboo.CMS.Form.IColumn column)
        {
            string input = base.RenderInput(column);
            string script = "<script src=\"@KB.Controls.ControlsScript.GetWebResourceUrl()\" type=\"text/javascript\" ></script>";

            input += String.Format(@"
                {0}
                <script type='text/javascript'>
                    $(function() {{
                        $('input[name=""{1}""]').datetimepicker({{
                            showSecond: true,
                            timeFormat: 'hh:mm:ss'
                        }});
                    }});
                </script>
            ", script, column.Name);
            return input;
        }
    }
}